package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappActRoutingEntity;
import com.infocollect.project.api.mapper.TappActRoutingMapper;
import com.infocollect.project.api.service.ITappActroutingService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TappActrouting)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:28
 */
@Service("tappActroutingService")
public class TappActRoutingServiceImpl extends ServiceImpl<TappActRoutingMapper, TappActRoutingEntity> implements ITappActroutingService {


    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappActRoutingEntity queryById(Long fid) {
        return this.baseMapper.selectById(fid);
    }


    /**
     * 新增数据
     *
     * @param tappActrouting 实例对象
     * @return 实例对象
     */
    @Override
    public TappActRoutingEntity insert(TappActRoutingEntity tappActrouting) {
        this.baseMapper.insert(tappActrouting);
        return tappActrouting;
    }

    /**
     * 修改数据
     *
     * @param tappActrouting 实例对象
     * @return 实例对象
     */
    @Override
    public TappActRoutingEntity update(TappActRoutingEntity tappActrouting) {
        this.baseMapper.updateById(tappActrouting);
        return this.queryById(tappActrouting.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     * @menu 根据实体对象是否有值 进行查询
     */
    @Override
    public List<TappActRoutingEntity> queryAll(TappActRoutingEntity entity) {
        return this.baseMapper.queryAll(entity);
    }

    public List<TappActRoutingEntity> queryByActID(Long actId){
        QueryWrapper<TappActRoutingEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("factid", actId);
        return this.baseMapper.selectList(queryWrapper);
    }
    /**
     * 根据节点ID 删除路由信息
     *
     * @param factid 根据节点ID 删除路由信息
     * @return 影响行数
     */
    @Override
    public int deleteByActID(Long factid) {
        QueryWrapper<TappActRoutingEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("factid", factid);
        return this.baseMapper.delete(queryWrapper);
    }
}